package com.github.zxhTom.demo.jol;

import java.util.ArrayList;
import java.util.List;

class S1{
    int age=2;
}
public class SynchronizedTest {
    static int index = 0;
    public static void main(String[] args) {
        List<Thread> threadList = new ArrayList<Thread>();
        for (int i = 0; i < 10000; i++) {
            final S1 s1 = new S1();
            Thread thread = new Thread(new Runnable() {
                public void run() {
                    synchronized (S1.class) {
                        index++;
                    }
                }
            });
            thread.start();
            threadList.add(thread);
        }
        for (Thread thread : threadList) {
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println(index);
    }
}
